package com.itholmes.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.itholmes.pojo.User;
import com.itholmes.pojo.log;
import com.itholmes.utils.ConnectionsPool;
import com.itholmes.utils.JDBCUtils;

public class LogDaoImpl {
	
	public void addLogUtil(User user,String log_execution,String log_type) {
		
		log log = new log();
		log.setLog_userid(user.getUser_id());
		log.setLog_execution(log_execution);
		log.setLog_type(log_type);
		String log_desc = "id为"+user.getUser_id()+"的用户，"+"进行了"+log_type+"操作";
		log.setLog_desc(log_desc);
		
		Connection connection = JDBCUtils.getConnection();
		PreparedStatement pre = null;
		
		try {
			
			pre = connection.prepareStatement("insert into `log` (log_userid,log_execution,log_type,log_desc) values (?,?,?,?)");
			pre.setInt(1, log.getLog_userid());
			pre.setString(2, log.getLog_execution());
			pre.setString(3, log.getLog_type());
			pre.setString(4, log.getLog_desc());
			
			int i = pre.executeUpdate();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		JDBCUtils.release(null, pre, null);
		//只要关闭了connection就要连接池中移除，不然会 报一个关闭后仍然运行的错误。
		ConnectionsPool.remove(connection);
	}
	
}
